const majorityElement = function(nums) {
    let num = 0, count = 0;
    for (let i = 0; i < nums.length; i++) {
        if (count == 0) {
            count ++;
            num = nums[i];
            continue;
        }
        if (nums[i] == num) {
            count ++;
        } else {
            count --;
        }
    }
    return num;
};

const nums1 = [3, 2, 3];  // output: 3
const nums2 = [2, 2, 1, 1, 1, 2, 2];  // output: 2


let inputs = [];
inputs.push(nums1);
inputs.push(nums2);

for (let i = 0; i < inputs.length; i++) {
    const res = majorityElement(inputs[i]);
    console.log(res);
}
